﻿using UnityEngine;
using System.Collections;
using Boomlagoon.JSON;

public class DataComponentParser {
	public DataComponentParser ()
	{

	}

	public AbstractDataComponent parseDataComponent (string dataComponentTypeStr , JSONObject dataComponentJsonObj)
	{
		DataComponentType dataComponentType = (DataComponentType)System.Enum.Parse(typeof(DataComponentType) , dataComponentTypeStr);
		AbstractDataComponent dataComponent = null;

		switch (dataComponentType)
		{
		case DataComponentType.CellState:
			dataComponent = new CellState();
			CellStateParser.parseCellState(dataComponentJsonObj , (CellState)dataComponent);
			break;
		case DataComponentType.CellStatic:
			dataComponent = new CellStatic();
			CellStaticParser.parseCellStatic(dataComponentJsonObj , (CellStatic)dataComponent);
			break;
		case DataComponentType.EntityState:
			dataComponent = new EntityState();
			EntityStateParser.parseEntityState(dataComponentJsonObj , (EntityState)dataComponent);
			break;
		case DataComponentType.EntityStatic:
			dataComponent = new EntityStatic();
			EntityStaticParser.parseEntityStatic(dataComponentJsonObj , (EntityStatic)dataComponent);
			break;
		case DataComponentType.LevelState:
			dataComponent = new LevelState();
			LevelStateParser.parseLevelState(dataComponentJsonObj , (LevelState)dataComponent);
			break;
		case DataComponentType.LevelStatic:
			dataComponent = new LevelStatic();
			LevelStaticParser.parseLevelStatic(dataComponentJsonObj , (LevelStatic)dataComponent);
			break;
		case DataComponentType.TransactableStatic:
			dataComponent = new TransactableStatic();
			TransactableStaticParser.parseTransactableStatic(dataComponentJsonObj , (TransactableStatic)dataComponent);
			break;
		case DataComponentType.UnitStatic:
			dataComponent = new UnitStatic();
			UnitStaticParser.parseUnitStatic(dataComponentJsonObj , (UnitStatic)dataComponent);
			break;
		}

		return dataComponent;
	}
}
